<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Docker 部署Nginx 并且挂载默认请求路径和配置文件 | MoneyLee’s Blog</title><meta name="author" content="李财"><meta name="copyright" content="李财"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="首先进入宿主机终端命令行 启动docker service docker start 查看已安装docker镜像列表 docker images  如果没有安装就安装下 docker pull nginx 然后得启动这个镜像 正常启动是下面的命令,但是先别着急敲 docker run -d -p 80:80 nginx 简单解释下这里面的值都代表啥意思 -d是让这个nginx容器服务后台运行 -p">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 部署Nginx 并且挂载默认请求路径和配置文件">
<meta property="og:url" content="https://moneylee.gitee.io/blog/2019/08/16/Docker%20%E9%83%A8%E7%BD%B2Nginx%20%E5%B9%B6%E4%B8%94%E6%8C%82%E8%BD%BD%E9%BB%98%E8%AE%A4%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/index.html">
<meta property="og:site_name" content="MoneyLee’s Blog">
<meta property="og:description" content="首先进入宿主机终端命令行 启动docker service docker start 查看已安装docker镜像列表 docker images  如果没有安装就安装下 docker pull nginx 然后得启动这个镜像 正常启动是下面的命令,但是先别着急敲 docker run -d -p 80:80 nginx 简单解释下这里面的值都代表啥意思 -d是让这个nginx容器服务后台运行 -p">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg">
<meta property="article:published_time" content="2019-08-16T05:12:02.000Z">
<meta property="article:modified_time" content="2019-12-11T02:06:29.000Z">
<meta property="article:author" content="李财">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://moneylee.gitee.io/blog/2019/08/16/Docker%20%E9%83%A8%E7%BD%B2Nginx%20%E5%B9%B6%E4%B8%94%E6%8C%82%E8%BD%BD%E9%BB%98%E8%AE%A4%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Docker 部署Nginx 并且挂载默认请求路径和配置文件',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2019-12-11 10:06:29'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/blog/atom.xml" title="MoneyLee’s Blog" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2019/11/10/SYvXMgCFuTNOVeZ.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">47</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/bbs/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-list"></i><span> 影音</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/music"><i class="fa-fw /music/"></i><span> 0</span></a></li><li><a class="site-page child" href="/blog/movies"><i class="fa-fw /movies/"></i><span> 1</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">MoneyLee’s Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/bbs/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-list"></i><span> 影音</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/music"><i class="fa-fw /music/"></i><span> 0</span></a></li><li><a class="site-page child" href="/blog/movies"><i class="fa-fw /movies/"></i><span> 1</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Docker 部署Nginx 并且挂载默认请求路径和配置文件</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-08-16T05:12:02.000Z" title="发表于 2019-08-16 13:12:02">2019-08-16</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2019-12-11T02:06:29.000Z" title="更新于 2019-12-11 10:06:29">2019-12-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/Docker/">Docker</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Docker 部署Nginx 并且挂载默认请求路径和配置文件"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>首先进入宿主机终端命令行 启动docker</p>
<p><code>service docker start</code></p>
<p>查看已安装docker镜像列表</p>
<p><code>docker images</code></p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sjoiuq3hj30hf01u74j.jpg"></p>
<p>如果没有安装就安装下</p>
<p><code>docker pull nginx</code></p>
<p>然后得启动这个镜像 正常启动是下面的命令,但是先别着急敲</p>
<p><code>docker run -d -p 80:80 nginx</code></p>
<p>简单解释下这里面的值都代表啥意思 <code>-d</code>是让这个nginx容器服务后台运行 <code>-p</code>是指定端口 后面跟的80:80 前面的80是宿主机的端口 后面的是容器里nginx的端口, 比如改成 8080:80 那么我们在外部访问这个nginx服务 地址应该是 <a target="_blank" rel="noopener" href="http://xx.xx.xx.xx:8080/">xx.xx.xx.xx:8080</a> 就可以看到nginx的欢迎页了</p>
<p><code>nginx</code>当然是启动的镜像名字啦</p>
<p>但是啊,这么写不好,如果你像改这个nginx的配置文件,或者改个静态页咋改啊,我们得到这个容器的内部去改啊, 简单说下如何进入这个容器的内部</p>
<p>先获取到这个nginx容器的id , 查询所有容器 无论是运行的还是exit的,其实在不在执行你都能看出来了,因为上面有exit标识着呢</p>
<p><code>docker ps -a</code></p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sjs03539j30hv02rq3h.jpg" alt="16aa0b5e75088978"></p>
<p>你看,映射的端口号都给你了,我这里面没有其他被关闭的容器服务,我有强迫症,都清理了,你也有的话执行这个命令 xxxxx是这个容器的id 图里有</p>
<p><code>docker rm xxxxx</code></p>
<p>扯这么多没用的,现在开始说重点的,如果去改这个nginx容器里的配置文件,日志文件的具体路径和内容呢,这就要使用到挂载,我理解的挂载的意思就是在使用这个nginx容器的时候,不去使用容器内的配置和文件路径,使用宿主机上的资源文件,对了 我还没说怎么去容器内,执行这个命令,对了 你要是不是root用户前面加 sudo</p>
<p><code>docker exec -it xxxx bash</code></p>
<p>xxxx是容器id</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sju4ig21j30ef02gjrr.jpg" alt="16aa0bd1e50158e8"></p>
<p>是不是有点眼熟 其实这个镜像自己的世界,不受外界打扰,但是功能指定没有宿主机全啊,比如你想在里面使用vim命令….</p>
<p>我们接着回来谈挂载,既然你想挂载,你得知道你镜像里面nginx的配置文件啥的都在哪吧,然后挂载到你宿主机的指定位置啊,所以我们先看看他们都在哪呢<br> 镜像中nginx.conf配置文件路径</p>
<p><code>/etc/nginx/nginx.conf</code></p>
<p>default.conf配置文件的路径</p>
<p><code>/etc/nginx/conf.d/default.conf</code></p>
<p>默认首页文件夹html路径</p>
<p><code>/usr/share/nginx/html</code></p>
<p>日志文件路径</p>
<p><code>/var/log/nginx</code></p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sjx7ip6rj30ec074mz9.jpg" alt="16aa0c396fe621b7"></p>
<p>来个图验证一下, 然后输入 <code>exit</code> 退出nginx容器回到宿主机</p>
<p>下面在宿主机上建挂载使用的文件夹</p>
<p><code>mkdir -p /nginx/&#123;conf,conf.d,html,logs&#125;</code></p>
<p>建这4个文件夹都知道是干啥用的了吧, 没权限记住前面加 <code>sudo</code></p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sjy43q42j30fg031dg9.jpg" alt="16aa0ccb2a0d8482"></p>
<p>下面就开始往对应的路径扔配置文件或者资源文件了,logs里不用,挂载好自动往里输出 error.log 和 access.log<br> html里你放首页需要展示的.html文件,然后你在访问,你加进来的html就把默认的nginx欢迎界面替换掉了…现在整没有用啊,你还没挂载呢,等会的。</p>
<p>conf里放 nginx.conf 配置文件, 这个文件的内容要从镜像里的复制出来哦,我们尽量保持和镜像里面的一致<br> 下面我们再来说说怎么将刚刚在容器里看到的配置文件copy到宿主机里面</p>
<p>前面是容器的路径 后面是宿主机的路径:</p>
<p><code>docker cp 容器id:/etc/nginx/nginx.conf /nginx/conf/nginx.conf</code></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attribute">user</span>  nginx;</span><br><span class="line"><span class="attribute">worker_processes</span>  <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="attribute">error_log</span>  /var/log/nginx/error.log <span class="literal">warn</span>;</span><br><span class="line"><span class="attribute">pid</span>        /var/run/nginx.pid;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="section">events</span> &#123;</span><br><span class="line">    <span class="attribute">worker_connections</span>  <span class="number">1024</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="section">http</span> &#123;</span><br><span class="line">    <span class="attribute">include</span>       /etc/nginx/mime.types;</span><br><span class="line">    <span class="attribute">default_type</span>  application/octet-stream;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">log_format</span>  main  <span class="string">&#x27;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#x27;</span></span><br><span class="line">                      <span class="string">&#x27;$status $body_bytes_sent &quot;$http_referer&quot; &#x27;</span></span><br><span class="line">                      <span class="string">&#x27;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#x27;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">access_log</span>  /var/log/nginx/access.log  main;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">sendfile</span>        <span class="literal">on</span>;</span><br><span class="line">    <span class="comment">#tcp_nopush     on;</span></span><br><span class="line"></span><br><span class="line">    <span class="attribute">keepalive_timeout</span>  <span class="number">65</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#gzip  on;</span></span><br><span class="line"></span><br><span class="line">    <span class="attribute">include</span> /etc/nginx/conf.d/<span class="regexp">*.conf</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>同样在把conf.d 下的default.conf 复制过来</p>
<p><code>docker cp 容器id:/etc/nginx/conf.d/default.conf /nginx/conf.d/default.conf</code></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span>       <span class="number">80</span>;</span><br><span class="line">    <span class="attribute">server_name</span>  localhost;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#charset koi8-r;</span></span><br><span class="line">    <span class="comment">#access_log  /var/log/nginx/host.access.log  main;</span></span><br><span class="line"></span><br><span class="line">    <span class="attribute">location</span> / &#123;</span><br><span class="line">        <span class="attribute">root</span>   /usr/share/nginx/html;</span><br><span class="line">        <span class="attribute">index</span>  index.html index.htm;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#error_page  404              /404.html;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># redirect server error pages to the static page /50x.html</span></span><br><span class="line">    <span class="comment">#</span></span><br><span class="line">    <span class="attribute">error_page</span>   <span class="number">500</span> <span class="number">502</span> <span class="number">503</span> <span class="number">504</span>  /50x.html;</span><br><span class="line">    <span class="attribute">location</span> = /50x.html &#123;</span><br><span class="line">        <span class="attribute">root</span>   /usr/share/nginx/html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span></span><br><span class="line">    <span class="comment">#</span></span><br><span class="line">    <span class="comment">#location ~ \.php$ &#123;</span></span><br><span class="line">    <span class="comment">#    proxy_pass   http://127.0.0.1;</span></span><br><span class="line">    <span class="comment">#&#125;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span></span><br><span class="line">    <span class="comment">#</span></span><br><span class="line">    <span class="comment">#location ~ \.php$ &#123;</span></span><br><span class="line">    <span class="comment">#    root           html;</span></span><br><span class="line">    <span class="comment">#    fastcgi_pass   127.0.0.1:9000;</span></span><br><span class="line">    <span class="comment">#    fastcgi_index  index.php;</span></span><br><span class="line">    <span class="comment">#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span></span><br><span class="line">    <span class="comment">#    include        fastcgi_params;</span></span><br><span class="line">    <span class="comment">#&#125;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># deny access to .htaccess files, if Apache&#x27;s document root</span></span><br><span class="line">    <span class="comment"># concurs with nginx&#x27;s one</span></span><br><span class="line">    <span class="comment">#</span></span><br><span class="line">    <span class="comment">#location ~ /\.ht &#123;</span></span><br><span class="line">    <span class="comment">#    deny  all;</span></span><br><span class="line">    <span class="comment">#&#125;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>然后,我们自己写一个简单的html页面,给他随意命个名,我就不改了,叫index.html</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sk0tyra8j309t07bgm3.jpg" alt="16aa10120b7d7dcb"></p>
<p>然后把这个文件丢到 宿主机的 <code>/nginx/html/</code> 路径下</p>
<p>我是用FileZilla工具传输文件到宿主机的</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sk1d4rvej30fo09djry.jpg" alt="16aa10469e7d8a51"></p>
<p>最后到了最关键的环节了</p>
<p>开始挂载了 我们先把之前起的nginx容器服务关闭了 我直接一点, <code>docker rm 容器id</code></p>
<p>OMG 我们得先关闭再删除,<code>docker stop 容器id</code></p>
<p>都弄好了之后再次启动 这次和上次不同之处就是需要用到 <code>-v</code> 进行挂载了</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker <span class="keyword">run</span><span class="bash"> --name mynginx -d -p 80:80 -v /nginx/html:/usr/share/nginx/html -v /nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /nginx/logs:/var/<span class="built_in">log</span>/nginx nginx</span></span><br></pre></td></tr></table></figure>

<p>前面是宿主机路径 后面的nginx容器路径</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwly1g9sk2m2eapj309b04faa6.jpg" alt="16aa4cac7a47445b"></p>
<p>我也是初学Java和Docker 哪有有不足请多指教,主要是给自己留个记录</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">李财</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://moneylee.gitee.io/blog/2019/08/16/Docker%20%E9%83%A8%E7%BD%B2Nginx%20%E5%B9%B6%E4%B8%94%E6%8C%82%E8%BD%BD%E9%BB%98%E8%AE%A4%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/">https://moneylee.gitee.io/blog/2019/08/16/Docker%20%E9%83%A8%E7%BD%B2Nginx%20%E5%B9%B6%E4%B8%94%E6%8C%82%E8%BD%BD%E9%BB%98%E8%AE%A4%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://moneylee.gitee.io/blog" target="_blank">MoneyLee’s Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2019/10/06/SpringBoot%20%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E5%86%85%20%E4%BD%BF%E7%94%A8@Autowired%E6%B3%A8%E5%85%A5Service%20%E8%8E%B7%E5%8F%96%E4%B8%8D%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/"><img class="prev-cover" src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">SpringBoot 定时任务内 使用@Autowired注入Service 获取不到的问题</div></div></a></div><div class="next-post pull-right"><a href="/blog/2019/08/10/U%E7%9B%98%E5%AE%89%E8%A3%85CentOS7.4/"><img class="next-cover" src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl6v5kt7j31g60squ0y.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">U盘安装CentOS 7.4</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2019/11/10/SYvXMgCFuTNOVeZ.png" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">李财</div><div class="author-info__description">嗨，我是李财 (MoneyLee)， 一名来自中国的 iOS开发者。</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">47</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/licai28" target="_blank" title=""><i class="fa fa-github"></i></a><a class="social-icon" href="mailto:licai_1024@hotmail.com" target="_blank" title=""><i class="fa fa-envelope"></i></a><a class="social-icon" href="/blog/img/mywechat.jpg" target="_blank" title=""><i class="fa fa-weixin"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/09/14/Flutter%20%E5%90%AF%E5%8A%A8%E9%A1%B5%E9%85%8D%E7%BD%AE/" title="无题"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="无题"/></a><div class="content"><a class="title" href="/blog/2021/09/14/Flutter%20%E5%90%AF%E5%8A%A8%E9%A1%B5%E9%85%8D%E7%BD%AE/" title="无题">无题</a><time datetime="2021-09-14T03:05:25.000Z" title="发表于 2021-09-14 11:05:25">2021-09-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/08/21/iOS%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" title="iOS机器学习"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="iOS机器学习"/></a><div class="content"><a class="title" href="/blog/2020/08/21/iOS%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" title="iOS机器学习">iOS机器学习</a><time datetime="2020-08-21T02:04:10.000Z" title="发表于 2020-08-21 10:04:10">2020-08-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/08/20/Docker%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%86/" title="Docker 基础知识整理"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl4zhjzuj30qy0e0gyz.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Docker 基础知识整理"/></a><div class="content"><a class="title" href="/blog/2020/08/20/Docker%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%86/" title="Docker 基础知识整理">Docker 基础知识整理</a><time datetime="2020-08-20T12:12:02.000Z" title="发表于 2020-08-20 20:12:02">2020-08-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/08/19/Flutter/" title="Flutter"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Flutter"/></a><div class="content"><a class="title" href="/blog/2020/08/19/Flutter/" title="Flutter">Flutter</a><time datetime="2020-08-19T02:04:03.000Z" title="发表于 2020-08-19 10:04:03">2020-08-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/08/19/iOS%20AR%E5%92%8CARKit4/" title="iOS AR和ARKit4"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g8vl0019wlj31ej0u0x6q.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="iOS AR和ARKit4"/></a><div class="content"><a class="title" href="/blog/2020/08/19/iOS%20AR%E5%92%8CARKit4/" title="iOS AR和ARKit4">iOS AR和ARKit4</a><time datetime="2020-08-19T02:04:03.000Z" title="发表于 2020-08-19 10:04:03">2020-08-19</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 李财</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>